package progress.exa28_1.part5;

/**
 * 定义Account类
 * 其中有两个同步方法，一个是普通同步方法，一个是静态同步方法
 * 使用synchronized关键字实现同步
 */
public class Account implements Runnable{

    private int money;

    private static int age;

    public synchronized void deposit(int i){
        money += i;
    }

    public static synchronized void deposit1(int i){
        age += i;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        deposit(5);
        deposit1(5);
    }

    @Override
    public String toString() {
        return "Account{" +
                "money=" + money +
                " age="+ age+
                '}';
    }

}
